package cn.icanci.controller;

import cn.icanci.entity.bo.HeadLine;
import cn.icanci.entity.dto.Result;
import cn.icanci.service.HeadLineService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * 头条Controller
 *
 * @author icanci
 * @date Created in 2021/02/04 00:12
 * @version 1.0
 */
@Controller
@RequestMapping(value = "/headline")
public class HeadLineOperationController {
    @Autowired
    private HeadLineService headLineService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ModelAndView addHeadLine(@RequestParam("lineName") String lineName, @RequestParam("lineLink") String lineLink, @RequestParam("lineImg") String lineImg,
                                    @RequestParam("priority") Integer priority) {
        HeadLine headLine = new HeadLine();
        headLine.setLineName(lineName);
        headLine.setLineLink(lineLink);
        headLine.setLineImg(lineImg);
        headLine.setPriority(priority);
        Result<Boolean> booleanResult = headLineService.addHeadLine(headLine);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("addheadline");
        modelAndView.addObject("result", booleanResult);
        return modelAndView;
    }

    @RequestMapping(value = "/open", method = RequestMethod.GET)
    public String openPage() {
        return "addheadline";
    }
}
